<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controlleradmin library
jimport('joomla.application.component.controlleradmin');
 
/**
* Categorys Controller
 */
class ShopControllerOrderes extends JControllerAdmin
{
	/**
	 * Proxy for getModel.
	 * @since	1.6
	 */
	public function getModel($name = 'Orderes', $prefix = 'ShopModel') 
	{
		$model = parent::getModel($name, $prefix, array('ignore_request' => true));
		return $model;
	}

	/**
	* Cancel save or new
	**/
	public function cancel()
	{
		$this->setRedirect('index.php?option=com_shop&view=orderes');
	}
	
	function delete()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
		// Initialise variables.
		$ids	= JRequest::getVar('cid', array(), '', 'array');
		$ids = implode(',',$ids);
		$db =& JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->delete('#__shop_order');
		$query->where("id in ($ids)");
		$db->setQuery((string)$query);
		if($db->query())
		{
			$this->setMessage(JText::_('COM_SHOP_ORDER_DELETE_SUCCESS'));
			$this->setRedirect('index.php?option=com_shop&view=orderes');
		}
		else
		{
			$this->setMessage(JText::_('COM_SHOP_ORDER_DELETE_FAIL'));
			$this->setRedirect('index.php?option=com_shop&view=orderes');
		}
	}
	
/**
	*	Call published
	*
	***/
	function publish()
	{
		 // Get items to publish from the request.
		$cid    = JRequest::getVar('cid', array(), '', 'array');
		$data    = array('publish' => 1, 'unpublish' => 0, 'archive'=> 2, 'trash' => -2, 'report'=>-3);
		  $task     = $this->getTask();
		  $value    = JArrayHelper::getValue($data, $task, 0, 'int');
		 if (empty($cid)) {
			 JError::raiseWarning(500, JText::_($this->text_prefix.'_NO_ITEM_SELECTED'));
		}
		else
		{
		
				$db = JFactory::getDBO();
				$query = $db->getQuery(true);

				$query->update('#__shop_banners');
				$query->set('state = '.$value);
				$query->where('id = '.intval($cid[0]));
				$db->setQuery((string)$query);
				//$db->query();
			 // Publish the items.
             if (!$db->query()) {
                  JError::raiseWarning(500, 'COM_SHOP_PUBLISHED_ERROR');
              }
              else {
                  if ($value == 1) {
                      $ntext = $this->text_prefix.'_N_ITEMS_PUBLISHED';
                  }
                  else if ($value == 0) {
                      $ntext = $this->text_prefix.'_N_ITEMS_UNPUBLISHED';
                  }
                  else if ($value == 2) {
                      $ntext = $this->text_prefix.'_N_ITEMS_ARCHIVED';
                  }
                 else {
                     $ntext = $this->text_prefix.'_N_ITEMS_TRASHED';
                  }
                  $this->setMessage(JText::plural($ntext, count($cid)));
             }
		}
		$this->setRedirect('index.php?option=com_shop&view=orderes');
		
	}
	
}